package com.zou.mall.product.web;

import com.alibaba.fastjson.JSON;
import com.zou.mall.product.entity.CategoryEntity;
import com.zou.mall.product.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author leonard
 * @date 2022/4/18
 * @Description 首页模板引擎联调跳转
 */
@Slf4j
@Controller
public class IndexController {

    @Resource
    private CategoryService categoryService;


    @GetMapping({"/","index.html"})
    public String indexPage(Model model){

        log.info("5000=========");

        //todo 查找所有的一级分类
        List<CategoryEntity> categoryEntityList = categoryService.getLevel1Catagories();


        //  通过viewResolver 进行拼串
        //	public static final String DEFAULT_PREFIX = "classpath:/templates/";
        //  public static final String DEFAULT_SUFFIX = ".html";
        //  classpath:/templates/ + return + .html
        model.addAttribute("catagories",categoryEntityList);
        log.info("indexPage-->:{}", JSON.toJSONString(categoryEntityList));
        return "index";
    }

}
